package 数组;

import java.util.Arrays;

/**
 * @Project: data-structure-and-algorithms
 * @Package: 数组
 * @ClassName: t345
 * @Author: zhouyihe
 * @Date: 2025/11/24 09:14
 * @Description: 反转字符串中的元音字母
 */
public class t345 {
    public static String reverseVowels(String s) {
        if (s.length() <= 1) {
            return s;
        }
        char[] chars = s.toCharArray();
        int left = 0;
        int right = chars.length - 1;
        while (left < right) {
            char l = Character.toLowerCase(chars[left]);
            char r = Character.toLowerCase(chars[right]);
            boolean lb = l == 'a' || l == 'e' || l == 'i' || l == 'o' || l == 'u';
            boolean rb = r == 'a' || r == 'e' || r == 'i' || r == 'o' || r == 'u';
            if (lb && rb) {
                char c = chars[left];
                chars[left] = chars[right];
                chars[right]= c;
                left++;
                right--;
            } else {
                if (!lb) {
                    left++;
                }
                if (!rb) {
                    right--;
                }

            }
        }
        return String.valueOf(chars);
    }

    public static void main(String[] args) {
        String s = "IceCreAm";
        System.out.println(reverseVowels(s));
    }
}
